<?php 
// baza bilan boglanish lock.php faylida yozilgan
include("lock.php");
include("../lang/uz.php");
/// xatolikni kursatish funk
function myerror($message){
echo ("<p style='color:#CC0000; border:1px solid red; margin:3px; padding:3px; background:#FFDFDF; font-family:Arial;'><b>
	 $message, <br>iltimos, bu haqida adminga xabar qiling: Leonardo73@rambler.ru </b><br></p>");
	 exit(mysql_error());
}
/// xatolikni kursatish finish 

/// adminda tovar ruyxatini kursat
function tovar($page) {
global $db;
global $cat;

if($page == "main") 
{ $query = "SELECT id,cat,title,date,price FROM data  WHERE custom='main' ORDER by id DESC";}
else if($page == "cat") 
{ $query = "SELECT id,cat,title,date,price FROM data WHERE cat='$cat' ORDER by id DESC";}
else if($page == "all") 
{ $query = "SELECT id,cat,title,date,price FROM data ORDER by id DESC";}
	
	$result = mysql_query($query, $db);
	if (!$result) { myerror("XATOLIK !!! Tovar functionda xatolik Bazadan malumotlar olinmadi. "); }
	
	if(mysql_num_rows($result) > 0)
	{
		while($myrow = mysql_fetch_array($result)) {
		printf("<tr> <td>
			<span class='tovar'> <label> <input name='checkbox[]' type='checkbox' value='%s' /> -   %s </label> </span> 
			<span class='price'> %s </span>
			<span class='view'><a href='tovar_edit.php?id=%s'> 
			<img src='img/edit.png' width='16' height='16' align='absmiddle' /> O'zgartirish </a></span>
			</td> </tr>", $myrow["id"], $myrow["title"], $myrow["price"], $myrow["id"]);
		}
	}
	else { 	echo NO_GOODS; 	}
}
/// adminda tovar ruyxatini kursat finish

/// delete qilish
function delete() {
	if (count($_POST['checkbox']) > 0) 
	{
		foreach ($_POST['checkbox'] as $del_id) 
		{
			// avval rasmni delete qilamiz
			$result3 = mysql_query("SELECT img_mini, img, img2, img3 FROM data WHERE id='$del_id'");
			$myrow3 = mysql_fetch_array($result3);
				
			$img_mini = "../".$myrow3['img_mini'];
			$img = "../".$myrow3['img'];
			$img2 = "../".$myrow3['img2'];
			$img3 = "../".$myrow3['img3'];
				
			if(!empty($myrow3['img_mini']))
			{
			@ unlink($img_mini);  @ unlink($img);  @ unlink($img2);  @ unlink($img3);
			$rasm_deleted = "Tovar Rasmlari ham o'chirildi"; 
			}
			// endi qatorni del qilamiz
			$result2 = mysql_query("DELETE FROM data WHERE id='$del_id'");
		}
	}
	else
	{
	echo "<p class='error'><b>XATOLIK !!! O'chirish uchun Tanlamadingiz</b></p>";
	}
	// if successful
	if($result2)
	{ 
	echo "<p class='ok'>Tanlangan tovar(lar) O'chirildi OK. ".$rasm_deleted."</p>";
	/*  yoki bu kod "<meta http-equiv=\"refresh\" content=\"0;URL=". $_SERVER['PHP_SELF'].'?cat='.$cat." \">";  
		yoki bu kod "<meta http-equiv=\"refresh\" content=\"0;URL=". $_SERVER['PHP_SELF'] ." \">";
	*/
	}
}
/// delete finish
?>